/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package reportingClasses;

/**
 *
 * @author hubert
 */
public class bodyTextWriter implements reportingObject{
    private java.io.File foreGroundFiles;
    private java.io.File backGroundFiles;
    private java.io.BufferedWriter writer;
    
    public void setForeGroundDir(String dir){
        this.foreGroundFiles = new java.io.File(dir);
    }
    
    public void setBackGroundDir(String dir){
        this.backGroundFiles = new java.io.File(dir);
    }
    
    public bodyTextWriter(){
    }
    public bodyTextWriter(String foreGrndDir, String bckGrndDir){
        this.setForeGroundDir(foreGrndDir);
        this.setBackGroundDir(bckGrndDir);
    }
    public void report(dataObjects.webArticle input){
        String targ = this.backGroundFiles.getAbsolutePath() + "/" + input.getKeyWord() + ".txt";
        if(input.isIsCancer()){
            targ = this.foreGroundFiles.getAbsolutePath() + "/" + input.getKeyWord() + ".txt";
        }
        this.writeBodyTextFile(input, new java.io.File(targ));
    }
    
    private void writeBodyTextFile(dataObjects.webArticle input, java.io.File targ){
        try{
            java.io.PrintWriter out = new java.io.PrintWriter(targ);
            out.write(input.getArticleText().toString());
            out.flush();
            out.close();
        }
        catch(java.io.FileNotFoundException e){
            System.out.println(input.getKeyWord() + " : " + input.getUrl());
            e.printStackTrace();
        }
    }
}
